﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class ParallelNodeHandler : CompositeNodeHandler
{
    public override BehaviorNodeState HandleComposite(BehaviorEntity entity,MultiBranchNodeData node)
    {
        node.CurIndex = node.ChildNodes.Count;
        for (int i = 0; i < node.ChildNodes.Count; i++)
        {
            GetChildNodeHandler(node.ChildNodes[node.CurIndex].CurNodeType).ExcuteNode(entity, node.ChildNodes[node.CurIndex]);
            if (node.ChildNodes[i].CurNodeState == BehaviorNodeState.Running)
            {
                node.CurIndex = i;
            }
        }
        if (node.CurIndex== node.ChildNodes.Count)
        {
            node.CurNodeState = BehaviorNodeState.Success;
        }
        else
        {
            node.CurNodeState = BehaviorNodeState.Running;
        }

        return node.CurNodeState;
    }
}